<?php
if(KT!='KhiThe') exit;

if(empty($_SESSION['lgSite'])){
	$_SESSION['lgSite'] = 'vietnamese';
}
if(isset($_GET['lg']) && ($_GET['lg']=='english' || $_GET['lg']=='vietnamese') ){
	$_SESSION['lgSite'] =$_GET['lg'];
}
define("dir_lang",$_SESSION['lgSite'],true);

function set_router($route_friendly, $router, $type=NULL, $arr_other=null)
{
	if($type==NULL)
	{
		if($_REQUEST ['kt'] == $route_friendly)
		$_REQUEST['kt'] = rtrim($router,'/');
		
	}
	else{
		
		if( ! in_array($route_friendly,$arr_other) )
		$_REQUEST['kt'] = rtrim($router . (isset($_REQUEST['kt'])?$_REQUEST['kt']:NULL),'/');;
		
	}
}

function __autoload($class_name)
{
	$amname = explode('_model',$class_name);
	$filem = path_module.'mod_'.$amname[0].'/'.$amname[0].'_model.php';
	if(file_exists($filem)) include $filem;
	
	$acname = explode('_controller',$class_name);
	$filec = path_module.'mod_'.$acname[0].'/'.$acname[0].'_controller.php';
	if(file_exists($filec)) include $filec;
}
function check_seo_com($menu,$SeoKey)
{
    $db = new khithe_mysql();
    $query = $db->SelectMySQL("SELECT comp FROM ".$menu." WHERE SeoKey='".$SeoKey."' ");
    $r = mysql_fetch_assoc($query);
    return isset($r['comp']) && $r['comp']!='systems'?$r['comp'].'/':'';
}

/* get route */
$rt = isset($_REQUEST['kt'])?$_REQUEST['kt']:NULL;
$arr_seo = explode('/', $rt);

//publics
$_com = check_seo_com(categorys, (isset($arr_seo[0])?str_replace('.html','',$arr_seo[0]):null) );

set_router($arr_seo[0], 'publics/'. $_com, '<>', array('publics','admin'));
set_router('publics/'. $arr_seo[0].'/','publics/'.$_com);

//sitemap.
set_router('publics/'. $_com .'sitemap.html','publics/sitemap');

$_seokey = explode('/', $_REQUEST['kt']);
if(isset($_SESSION['Mod']) && isset($_seokey[0]) && $_SESSION['Mod']=='Members' && $_seokey[0] == 'admin'){
	
	if($_seokey[1] != 'news')
	{
		echo 'Bạn không có quyền';
		exit(); 
	}
}
